package com.example.volleyball;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.volleyball.Tools.Tools;

import java.util.List;

public class AboutAdapter extends ArrayAdapter<Tools> {

    Context context;

    public AboutAdapter(@NonNull Context context, int resource, List<Tools> data) {
        super(context, resource,data);
        this.context = context;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_yuyue,parent,false);
            TextView time = view.findViewById(R.id.time);
            TextView hour = view.findViewById(R.id.hour);
            TextView field = view.findViewById(R.id.field);
            TextView name = view.findViewById(R.id.name);
            holder = new ViewHolder(time,field,hour,name);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder)view.getTag();
        }
        Tools tools = getItem(position);
        if (tools != null){
            holder.time.setText(tools.time);
            holder.hour.setText(tools.hour);
            holder.field.setText(tools.field);
            holder.name.setText(tools.name);
        }
        return view;
    }

    public class ViewHolder{

        TextView time;
        TextView field;
        TextView hour;
        TextView name;

        public ViewHolder(TextView time,TextView field,TextView hour,TextView name){
            this.field = field;
            this.hour = hour;
            this.name = name;
            this.time = time;
        }

    }
}
